import js from "@eslint/js";
import prettier from "eslint-config-prettier";
import pluginPrettier from "eslint-plugin-prettier/recommended";
import { defineConfig, globalIgnores } from "eslint/config";
import globals from "globals";
import tseslint from "typescript-eslint";

export default defineConfig([
  globalIgnores([
    "**/dist/**", // 任何目录下的dist文件夹
    "**/node_modules/**", // 任何目录下的node_modules文件夹
    "**/public/**", // 任何目录下的public文件夹
  ]),
  {
    files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
    plugins: { js },
    // ESLint JavaScript 推荐配置预设
    extends: ["js/recommended"],
    rules: {},
    languageOptions: {
      globals: {
        ...globals.browser,
        ...globals.node, // 同时支持两种环境
      },
    },
  },
  prettier,
  pluginPrettier,
  ...tseslint.configs.recommended,
  // 覆盖TypeScript规则
  {
    files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
    rules: {
      // 允许使用require导入
      "@typescript-eslint/no-require-imports": "off",
      // 允许使用any类型
      "@typescript-eslint/no-explicit-any": "off",
      // 允许使用不安全的函数类型
      "@typescript-eslint/no-unsafe-function-type": "off",
    },
  },
]);
